package com.lzl.staservice.schedule;

import com.lzl.staservice.service.StatisticsDailyService;
import com.lzl.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTask {

    /**
     * 测试
     * 0/5 * * * * ? 表示每隔5秒执行一次这个方法
     */
//    @Scheduled(cron = "0/5 * * * * ?")
    public void task1() {
        System.out.println("*********++++++++++++*****执行了");
    }


    @Autowired
    private StatisticsDailyService staService;

    //在每天凌晨一点，把前一天的数据---执行统计方法-把数据进行添加到数据库
//    @Scheduled(cron = "0 0 1 * * ?")
    public void task2() {
        staService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
    }

}
